package com.cote.douhahou.pretloan.beans

import com.google.gson.Gson
import com.cote.douhahou.pretloan.any.util.AkomapalendAnalyticsUtil
import com.cote.douhahou.pretloan.utils.AkomapaLendConfigs
import com.cote.douhahou.pretloan.utils.AkomapaLendUtil
import okhttp3.MediaType.Companion.toMediaTypeOrNull
import okhttp3.RequestBody
import okhttp3.RequestBody.Companion.toRequestBody

open class AakomapalendPamBase(

    var path: String = "",
    var aduid: String = "",
    var androidId: String = "",
    var token: String = "",
    var isLimitAdTrackingEnabled: String = "",
    var apiVersion: String = "v3",
    var userId: String = "",
    var product: String = "",
    var aduidPath: String = "",
    var advertId: String = "",
    var version: String = "",
    var clientType: String = ""

) {
    init {

        this.userId = AkomapaLendUtil.userId()
        this.aduidPath = AkomapalendAnalyticsUtil.androidId()
        this.aduid = AkomapalendAnalyticsUtil.adId()
        this.androidId = AkomapalendAnalyticsUtil.androidId()
        this.clientType = "ANDROID"
        this.version = AkomapaLendConfigs.AkomapalendVERSION
        this.advertId = AkomapalendAnalyticsUtil.adId()
        this.isLimitAdTrackingEnabled = AkomapalendAnalyticsUtil.adEnabled().toString()
        this.token = AkomapaLendUtil.token()
        this.product = AkomapaLendConfigs.MyProduct

    }

    open fun toEncryptParams(path1: String): String {
        val path2 = path1.replace("/".toRegex(), "")
        path = path2
        val content = Gson().toJson(this).trim()
        return AkomapaLendUtil.aesEncrypt(content)
    }

    open fun toRequestBody(path: String): RequestBody {
        val encrypted: String = toEncryptParams(path)
        val mediaType = "text/plain".toMediaTypeOrNull()
        return encrypted.toRequestBody(mediaType)
    }
}